package com.adds.lvds.service.impl.organize;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.adds.lvds.core.plugin.PageView;
import com.adds.lvds.core.utils.CommUtils;
import com.adds.lvds.dao.impl.organize.OrganizeInfoMapper;
import com.adds.lvds.dao.impl.organize.SysUserInfoMapper;
import com.adds.lvds.model.organize.SysOrgInfo;
import com.adds.lvds.model.organize.SysOrgUser;
import com.adds.lvds.model.organize.SysUserInfo;

@Service("sysUserInfoService")
@SuppressWarnings("all")
public class SysUserInfoService {

	@Autowired
	private SysUserInfoMapper sysUserInfoMapper;
	@Autowired
	private OrganizeInfoMapper organizeInfoMapper;

	/**
	 * 分页
	 */
	public PageView<SysUserInfo> query(PageView<SysUserInfo> pageView,
			SysUserInfo t) {
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("paging", pageView);
			map.put("t", t);
			List<SysUserInfo> list = sysUserInfoMapper.pageSysUserInfo(map);
			pageView.setRecords(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageView;
	}

	/**
	 * 根据id删除信息
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public String batchDelUserInfoByEmpId(String ids) {
		String result = CommUtils.SUCC;
		try {
			sysUserInfoMapper.batchDelUserInfoByEmpId(ids.split(","));

		} catch (Exception e) {
			result = CommUtils.ERROR;
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 根据id修改信息
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public String updateUserInfo(SysUserInfo sysUserInfo) {
		String result = CommUtils.SUCC;
		try {
			sysUserInfoMapper.updateUserInfo(sysUserInfo);
		} catch (Exception e) {
			result = CommUtils.ERROR;
			e.printStackTrace();
		}
		return result;

	}

	/**
	 * 添加成员信息
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public String addUserInfo(SysUserInfo sysUserInfo, SysOrgUser sysOrgUser) {
		String result = CommUtils.SUCC;
		try {
			sysUserInfoMapper.addUserInfo(sysUserInfo);
			organizeInfoMapper.insertSysOrgUser(sysOrgUser);
		} catch (Exception e) {
			result = CommUtils.ERROR;
			throw new RuntimeException();

		}
		return result;

	}

	public List<SysUserInfo> findSysUserInfoByMap(Map<String, Object> map) {
		List<SysUserInfo> list = null;
		try {
			list = sysUserInfoMapper.findSysUserInfoByMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 根据条件查询成员数据
	 * 
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public SysUserInfo querySysUserInfoByMap(Map<String, Object> map) {
		SysUserInfo sysUserInfo = null;
		try {
			sysUserInfo = sysUserInfoMapper.querySysUserInfoByMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysUserInfo;
	}

	/**
	 * 根据emp_id获取部门数据
	 * 
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public SysOrgInfo findSysOrgByEmpId(String emp_id) {
		SysOrgInfo sysOrgInfo = null;
		try {
			sysOrgInfo = sysUserInfoMapper.findSysOrgByEmpId(emp_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysOrgInfo;
	}

	/**
	 * 根据emp_id Info获取信息
	 * 
	 * @param emp_id
	 * @return
	 * @throws Exception
	 */
	public SysUserInfo getByInfoId(String emp_id) {
		SysUserInfo sysUserInfo = null;
		try {
			sysUserInfo = sysUserInfoMapper.getByInfoId(emp_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysUserInfo;
	}

	/**
	 * 根据查询条件获取所有值
	 * 
	 * @param map
	 * @return
	 */

	public List<SysUserInfo> getSysUserInfoListByMap(Map<String, Object> map) {
		return sysUserInfoMapper.getSysUserInfoListByMap(map);
	}

}
